#include <avr/io.h>
#include "../avrx/avrx.h"
#include "main.h"

#define TICKRATE 1000	// time 1 ms
// Peripheral initialization
#define TCNT_INIT (0xFF-((F_CPU/256)/TICKRATE))

//AVRX_EXTERNTASK(KeyInTask);
//AVRX_EXTERNTASK(RTC_Task);
//AVRX_EXTERNTASK(SerialTask);
AVRX_EXTERNTASK(DispTask);
AVRX_EXTERNTASK(MainTask);

AVRX_SIGINT(TIMER0_OVF_vect)
{
    IntProlog();                // Switch to kernel stack/context
    TCNT0 = TCNT_INIT;
    AvrXTimerHandler();         // Call Time queue manager
    Epilog();                   // Return to tasks
}

int main(void)
{
    AvrXSetKernelStack(0);

	MCUCR = _BV(SE);
	TCNT0 = TCNT_INIT;
	TCCR0 =  (1<<CS02);         //clk/256 (From prescaler)
	TIMSK = _BV(TOIE0);


	//AvrXRunTask( TCB( RTC_Task	) );
	//AvrXRunTask( TCB( SerialTask	) );
   // AvrXRunTask( TCB( KeyInTask	) );
	AvrXRunTask( TCB( DispTask	) );
    AvrXRunTask( TCB( MainTask	) );
	Epilog();
    
	while(1);
}

